export class _Cache<T extends object, U> {

    cacheMap: WeakMap<T, U>

    constructor() {
        this.cacheMap = new WeakMap<T, U>()
    }

    readOrSet(obj: T, cb: () => U) {
        if(this.cacheMap.has(obj)) {
            return this.cacheMap.get(obj)
        }
        else {
            let val = cb()
            this.cacheMap.set(obj, val)
            return val
        }
    }

}